package com.awspaas.user.apps.cpq.controller;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.math.NumberUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.bpmn.engine.model.run.delegate.ProcessInstance;
import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.exception.BPMNError;
import com.actionsoft.sdk.local.SDK;
import com.alibaba.fastjson.JSONObject;

public class CPQ_GetgetMouleMsgWeb {

	public String getMouleMsg(UserContext userContext, String bindId, String datas,String type,String dz) {
		try {
			JSONObject jsonObject= JSONObject.parseObject(datas);
			 ResponseObject ro = ResponseObject.newOkResponse();
			List<BO> bos=SDK.getBOAPI().query("BO_EU_CPQ_PROJECT_MSG_PARAMETER_GRIDS").bindId(bindId).list();
			String bh=jsonObject.getString("MKBH");
			if(type.equals("否")) {
				BO data=SDK.getBOAPI().query("BO_EU_CPQ_MODULE_RECORD").addQuery("MKBM=", bh).addQuery("GLPID=", bindId).detail();
				if(null!=data) {
					//获取已存在的参数
					Map<String, String> map=new HashMap<String, String>();
					if(bos.size()>0) {
						for (BO bo : bos) {
							map.put(bo.getString("PARMENTIER_NO"), bo.getString("PARMENTIER_VALUE"))	;
						}
					}
					String pid=data.getBindId();
					List<BO> lists=SDK.getBOAPI().query("BO_EU_CPQ_MODULE_RECORD_PARAMETERS").bindId(pid).list();
					//存在参数后，判断参数在报价单的参数列表中是否存在
					Map<String, String> change=new HashMap<String, String>();
					if(lists.size()>0) {
						for (BO bo : lists) {
							String bm=bo.getString("PARMENTIER_NO");
							if(map.containsKey(bm)) {
								change.put(bo.getId(), map.get(bm));
							}
						}
					}
					String pids=data.getBindId();
					List<BO>gards =SDK.getBOAPI().query("BO_EU_CPQ_MODULE_RECORD_STRAIGHT_HAIR").bindId(pids).list();
					if(gards.size()>0) {

						List<BO> maps =SDK.getBOAPI().query("BO_EU_CPQ_TRANSPORT").list();
						Map<String, String> map2=new HashMap<>();
						if(maps.size()>0) {
							for (BO bo : maps) {
								String mc=bo.getString("MC");
								String sf=bo.getString("MDSF");
								map2.put(mc+":"+sf, bo.getString("YFBZ"));
							}
						}
						for (BO bo : gards) {
							String mc=bo.getString("MC");
							String SL=bo.getString("SL");

							String pirce="0";
							if(map2.containsKey(mc+":"+dz)) {
								 pirce=map2.get(mc+":"+dz);
							}
							 BigDecimal prices = new BigDecimal(pirce);
		        			 BigDecimal sl = new BigDecimal(SL);
							bo.set("MDSF", dz);
							bo.set("YFBZ", prices);
							bo.set("YFJG", prices.multiply(sl));
							SDK.getBOAPI().update("BO_EU_CPQ_MODULE_RECORD_STRAIGHT_HAIR",bo );
						}
					}

					 Map<String, Object> maps = new HashMap<String, Object>();
				        maps.put("bindId", pid);
				        maps.put("change", change);
				        ro.put("data", maps);


				}else {
					//不存在则需要创建该模块记录信息
					BO mdata=SDK.getBOAPI().query("BO_EU_CPQ_PROJECT_MSG").bindId(bindId).detail();
					BO mkdata=SDK.getBOAPI().query("BO_EU_CPQ_MODULE_MSG").addQuery("MKBM=", bh).addQuery("STATUS=", "启用").detail();
					String wlsql = "select  m.MKBM,m.SL,m.WLJSGS,m.XH, w.BM,w.NAME,w.TYPE,w.GG,w.TH,w.DW,w.CLF,w.RGF,w.WXWG,w.CGF,w.DJ from BO_EU_CPQ_COMPONENT_PART w,(" +
							"select  a.MKBM,b.XH,b.WLMC,b.WLBM,b.LX,b.GG,b.DH,b.DW,b.SL,b.DJ,b.WLJSGS,b.CLF,b.RGF,b.WXWG,b.CGF"
							+ " from BO_EU_CPQ_MODULE_MSG_GRID  b left JOIN   BO_EU_CPQ_MODULE_MSG a on b.BINDID=a.BINDID "
							+ "where a.STATUS='启用' and a.MKBM in ('" + bh + "')  ) m where w.BM=m.WLBM";
					System.out.println("物料sql："+wlsql);
					String zfsql = "select  a.MKBM,b.* from BO_EU_BO_EU_CPQ_MODULE_MSG_STRAIGHT_HAIR   b left JOIN BO_EU_CPQ_MODULE_MSG a on b.BINDID=a.BINDID "
							+ "where   a.STATUS='启用' and a.MKBM in ('" + bh + "')";
					String cssql = "select  a.MKBM,b.* from BO_EU_CPQ_MODULE_MSG_PRICE_PARAMETERS   b left JOIN BO_EU_CPQ_MODULE_MSG a on b.BINDID=a.BINDID "
							+ "where   a.STATUS='启用' and a.MKBM in ('" + bh + "')";
					List<RowMap> wlmaps = DBSql.getMaps(wlsql);
					Map<String,List<RowMap>> wlmoduleMap = new HashMap<>();
					if (wlmaps.size() > 0) {
						for (RowMap rowMap : wlmaps) {
							String mkbm = rowMap.getString("MKBM");
							if(wlmoduleMap.containsKey(mkbm)) {
								List<RowMap> list=wlmoduleMap.get(mkbm);
								list.add(rowMap);
							}else {
								List<RowMap> list=new ArrayList<RowMap>();
								list.add(rowMap);
								wlmoduleMap.put(mkbm, list);
							}

						}
					}
					List<RowMap> zfmaps = DBSql.getMaps(zfsql);
					Map<String, List<RowMap>> zfmoduleMap = new HashMap<>();
					if (zfmaps.size() > 0) {
						for (RowMap rowMap : zfmaps) {
							String mkbm = rowMap.getString("MKBM");
							if(zfmoduleMap.containsKey(mkbm)) {
								List<RowMap> list=zfmoduleMap.get(mkbm);
								list.add(rowMap);
								zfmoduleMap.put(mkbm, list);
							}else {
								List<RowMap> list=new ArrayList<RowMap>();
								list.add(rowMap);
								zfmoduleMap.put(mkbm, list);
							}
						}
					}
					List<RowMap> csmaps = DBSql.getMaps(cssql);
					System.out.println("csmaps:"+csmaps.toString());
					Map<String, RowMap> csmoduleMap = new HashMap<>();
					if (csmaps.size() > 0) {
						for (RowMap rowMap : csmaps) {
							String mkbm = rowMap.getString("PARMENTIER_NO");
								csmoduleMap.put(mkbm, rowMap);
						}
					}
					//遍历参数信息
					Map<String, JSONObject> pMap = new HashMap<String, JSONObject>();
					Map<String, String> nameMap = new HashMap<String, String>();
					Map<String, String> noMap = new HashMap<>();
					Map<String, List<BO>> wlMaps=new HashMap<>();
					Map<String, List<BO>> zfMaps=new HashMap<>();
					Map<String, List<BO>> csMaps=new HashMap<>();
					if(bos.size()>0) {
						for (int i = 0; i < bos.size(); i++) {
							//JSONObject json = (JSONObject) list.get(i);
							BO json =  bos.get(i);
							String bm = json.getString("PARMENTIER_NO");
							String value =  json.getString("PARMENTIER_VALUE");
							String name =  json.getString("PARMENTIER_NAME");
							String dw =  json.getString("DW");
							JSONObject jsonObject1=new JSONObject();
							//判断value是否为数据
							if( NumberUtils.isCreatable(value)) {
								jsonObject1.put("type", "1");//值为1者表示value为数值
							}else {
								jsonObject1.put("type", "0");//值为0者表示value为字符串
							}
							jsonObject1.put("value", value);
							pMap.put(bm, jsonObject1);
							nameMap.put(bm, name);
							int num = i + 1;
							noMap.put(bm, "B$" + num);
						}
						System.out.println("pMap:"+pMap.toString());
					}
					//再次遍历参数判断是否存在如果存则修改参数信息，如果没有则添加
					Map<String, String> changeMap = new HashMap<>();
					if (csmaps.size() > 0) {
						for (int i = 0; i < csmaps.size(); i++) {
							RowMap rowMap=csmaps.get(i);
							String bm = rowMap.getString("PARMENTIER_NO");
							String value =  rowMap.getString("PARMENTIER_VALUE");
							String name =  rowMap.getString("PARMENTIER_NAME");
							String dw =  rowMap.getString("DW");
							JSONObject jsonObject1=new JSONObject();
							//判断value是否为数据
							if( NumberUtils.isCreatable(value)) {
								jsonObject1.put("type", "1");//值为1者表示value为数值
							}else {
								jsonObject1.put("type", "0");//值为0者表示value为字符串
							}
							jsonObject1.put("value", value);
							if(pMap.containsKey(bm)) {
								changeMap.put(bm, value);
							}else {
								pMap.put(bm, jsonObject1);
								nameMap.put(bm, name);
								int num = bos.size()+i + 1;
								noMap.put(bm, "B$" + num);
							}
						}
					}
					Workbook workbookwl = new XSSFWorkbook();
					Workbook workbook = new XSSFWorkbook();
					try {
						Sheet sheet = workbookwl.createSheet("Sheet1");
						for (int i = 0; i < bos.size(); i++) {
							int num = i + 1;
							Cell cellB1 = sheet.createRow(i).createCell(1);
							//JSONObject jsonObject = (JSONObject) list.get(i);
							BO jsonObject1 =  bos.get(i);
							String bm =  jsonObject1.getString("PARMENTIER_NO");
							JSONObject jsonObject2=	pMap.get(bm);
							String lx=jsonObject2.getString("type");
							if(lx.equals("0")) {
								cellB1.setCellValue(jsonObject2.getString("value"));
								System.out.println("cellB1:"+cellB1.getStringCellValue());
							}else {
								String value=jsonObject2.getString("value");
								double  numValue=Double.parseDouble(value);
								 cellB1.setCellValue(numValue);
								 System.out.println("cellB1:"+cellB1.getNumericCellValue());
							}

						}
						//对参数数据进行创建
						List<BO> cslists=new ArrayList<>();
							if(csmaps.size()>0) {
								for (RowMap rowMap2 : csmaps) {
									BO cs=new BO();
									String no=rowMap2.getString("PARMENTIER_NO");
									JSONObject jsonObject2=	pMap.get(no);
									cs.set("PARMENTIER_NAME", rowMap2.getString("PARMENTIER_NAME"));
									cs.set("PARMENTIER_NO", no);
									cs.set("PARMENTIER_VALUE", jsonObject2!=null?jsonObject2.getString("value"):rowMap2.getString("PARMENTIER_VALUE"));
									cs.set("DW", rowMap2.getString("DW"));
									cs.set("BZ", rowMap2.getString("BZ"));
									cs.set("XH", rowMap2.getString("XH"));
									cslists.add(cs);
								}
								csMaps.put(bh, cslists);
							}

						//判断模块中是否有物料数据
						List<BO> lists=new ArrayList<>();
						int size=0;
						BigDecimal mkdj=new BigDecimal("0");
						BigDecimal clf1=new BigDecimal("0");
						BigDecimal rgf1=new BigDecimal("0");
						BigDecimal wxf=new BigDecimal("0");
						BigDecimal cgf1=new BigDecimal("0");
						BigDecimal zfwz=new BigDecimal("0");
						if(wlmoduleMap.containsKey(bh)) {
					    	List<RowMap> materials=wlmoduleMap.get(bh);
					    	if(materials.size()>0) {
					    		size=materials.size();
					    		for (int i = 0; i < materials.size(); i++) {
					    			RowMap bo = materials.get(i);
					    			BO wlgrid=new BO();
					    			String price1 = bo.getString("DJ").isEmpty()?"0":bo.getString("DJ");
									String clf = bo.getString("CLF").isEmpty()?"0":bo.getString("CLF");
									String rgf = bo.getString("RGF").isEmpty()?"0":bo.getString("RGF");
									String wx = bo.getString("WXWG").isEmpty()?"0":bo.getString("WXWG");
									String cgf = bo.getString("CGF").isEmpty()?"0":bo.getString("CGF");
									String sl = bo.getString("SL").isEmpty()?"0":bo.getString("SL");
									//b.XH,b.WLMC,b.WLBM,b.LX,b.GG,b.DH,b.DW,b.SL,b.DJ,b.WLJSGS,b.CLF,b.RGF,b.WXWG,b.CGF
									wlgrid.set("XH",bo.getString("XH") );
									wlgrid.set("WLMC", bo.getString("NAME"));
									wlgrid.set("WLBM", bo.getString("BM"));
									wlgrid.set("LX", bo.getString("TYPE"));
									wlgrid.set("GG", bo.getString("GG"));
									wlgrid.set("DH", bo.getString("TH"));
									wlgrid.set("DW", bo.getString("DW"));
									wlgrid.set("DJ", price1);
									wlgrid.set("CLF", clf);
									wlgrid.set("RGF",rgf );
									wlgrid.set("WXWG",wx );
									wlgrid.set("CGF",cgf );
									wlgrid.set("WLJSGS",bo.getString("WLJSGS") );
									//w.BM,w.NAME,w.TYPE,w.GG,w.TH,w.DW
					    			String equation = bo.getString("WLJSGS");
									  Document document = Jsoup.parse(equation);
									  String newQuation=document.text();
									  if (!newQuation.equals("0")&&!newQuation.isEmpty()) {
										  System.out.println("参数计算公式："+newQuation);
											// 获取物料数量计算公式中参数代号，如果有则将代号存放在list中
											for (String key : pMap.keySet()) {
												int num = newQuation.indexOf(key);
												if (num > -1) {
													newQuation = newQuation.replace(key, noMap.get(key));
												}
											}
											System.out.println("转换后的参数计算公式："+newQuation);
											FormulaEvaluator formulaEvaluator = workbookwl.getCreationHelper().createFormulaEvaluator();
											Cell cellB1 = sheet.createRow(bos.size()+i).createCell(2);
											cellB1.setCellFormula(newQuation);
											formulaEvaluator.evaluateFormulaCell(cellB1);
											// 获取公式计算结果
											CellValue cellValue = formulaEvaluator.evaluate(cellB1);
											System.out.println("The result of the formula is: " + cellValue.getNumberValue());
											double total1 = Double.parseDouble(price1) * cellValue.getNumberValue();
											double clftotal1 = Double.parseDouble(clf) * cellValue.getNumberValue();
											double rgftotal = Double.parseDouble(rgf) * cellValue.getNumberValue();
											double wxtotal = Double.parseDouble(wx) * cellValue.getNumberValue();
											double cgftotal = Double.parseDouble(cgf) * cellValue.getNumberValue();
											System.out.println("物料名称:"+bo.getString("WLMC")+"单价："+price1+",总价："+total1);
											wlgrid.set("SL", cellValue.getNumberValue());
											wlgrid.set("ZJ",total1);
											wlgrid.set("ZCLF",clftotal1);
											wlgrid.set("ZGSF",rgftotal);
											wlgrid.set("ZWX",wxtotal);
											wlgrid.set("ZCGF",cgftotal);
											BigDecimal mkdj2=new BigDecimal(total1);
											BigDecimal clf2=new BigDecimal(clftotal1);
											BigDecimal rgf2=new BigDecimal(rgftotal);
											BigDecimal wxf2=new BigDecimal(wxtotal);
											BigDecimal cgf2=new BigDecimal(cgftotal);
											mkdj=mkdj.add(mkdj2);
											clf1=clf1.add(clf2);
											rgf1=rgf1.add(rgf2);
											wxf=wxf.add(wxf2);
											cgf1=cgf1.add(cgf2);
									  }else {
										  double num = Double.parseDouble(sl);
										  double total1 = Double.parseDouble(price1) * num;
											double clftotal1 = Double.parseDouble(clf) * num;
											double rgftotal = Double.parseDouble(rgf) * num;
											double wxtotal = Double.parseDouble(wx) * num;
											double cgftotal = Double.parseDouble(cgf) * num;
											wlgrid.set("SL", sl);
											wlgrid.set("ZJ",total1);
											wlgrid.set("ZCLF",clftotal1);
											wlgrid.set("ZGSF",rgftotal);
											wlgrid.set("ZWX",wxtotal);
											wlgrid.set("ZCGF",cgftotal);
											BigDecimal mkdj2=new BigDecimal(total1);
											BigDecimal clf2=new BigDecimal(clftotal1);
											BigDecimal rgf2=new BigDecimal(rgftotal);
											BigDecimal wxf2=new BigDecimal(wxtotal);
											BigDecimal cgf2=new BigDecimal(cgftotal);
											mkdj=mkdj.add(mkdj2);
											clf1=clf1.add(clf2);
											rgf1=rgf1.add(rgf2);
											wxf=wxf.add(wxf2);
											cgf1=cgf1.add(cgf2);
									  }
									  lists.add(wlgrid);
					    		}
					    	}
					}
						//对直发物资进行计算
						List<BO> mapss =SDK.getBOAPI().query("BO_EU_CPQ_TRANSPORT").list();
						Map<String, String> map2=new HashMap<>();
						if(mapss.size()>0) {
							for (BO bo : mapss) {
								String mc=bo.getString("MC");
								String sf=bo.getString("MDSF");
								map2.put(mc+":"+sf, bo.getString("YFBZ"));
							}
						}
						List<BO> zflist=new ArrayList<>();
						BigDecimal zzyf=new BigDecimal("0");
						if(zfmoduleMap.containsKey(bh)) {
							List<RowMap> list=zfmoduleMap.get(bh);
							if(list.size()>0) {
								for (int i = 0; i < list.size(); i++) {
									RowMap rowMap =  list.get(i);
									BO zfgrid=new BO();
									String mc=rowMap.getString("MC");
									String yfdj="0";//运费单价；
									if(map2.containsKey(mc+":"+dz)) {
										 yfdj=rowMap.getString("YFBZ").isEmpty()?"0":rowMap.getString("YFBZ");//运费单价；
									}

									 String SL=rowMap.getString("SL").isEmpty()?"0":rowMap.getString("SL");//运费单价；
				        			 BigDecimal price = new BigDecimal(yfdj);
				        			 BigDecimal sl = new BigDecimal(SL);


								    zfgrid.set("MC", rowMap.getString("MC"));
								    zfgrid.set("ZL", rowMap.getString("ZL"));
								    zfgrid.set("DW", rowMap.getString("DW"));
								    zfgrid.set("YFBZ", price);
								    zfgrid.set("BZ", rowMap.getString("BZ"));
								    zfgrid.set("BM", rowMap.getString("BM"));
									// 计算出物料数量和当前模块的物料成本价格
										 zfgrid.set("YFJG",price.multiply(sl));
										 zfgrid.set("MDSF",dz);
										 zfgrid.set("SL",sl);
									     zfwz.add(price.multiply(sl));
									     zflist.add(zfgrid);
									     zzyf=zzyf.add(price.multiply(sl));
									}

								}
							}


						//创建模块信息
						BO mkBo=new BO();
						mkBo.set("SSXT", mkdata.getString("SSXT"));
						mkBo.set("PMKSSDL", mkdata.getString("PMKSSDL"));
						mkBo.set("MKMC", mkdata.getString("MKMC"));
						mkBo.set("MKBM", mkdata.getString("MKBM"));
						mkBo.set("GG", mkdata.getString("GG"));
						mkBo.set("DW", mkdata.getString("DW"));
						mkBo.set("CLF", clf1);
						mkBo.set("RGF", rgf1);
						mkBo.set("WXWG", wxf);
						mkBo.set("CGF", cgf1);
						mkBo.set("ZFWZYF", zfwz);
						mkBo.set("MKDJ", mkdj.add(zzyf));
						mkBo.set("ZZFBL", mkdata.getString("ZZFBL"));
						String bl=mkdata.getString("ZZFBL").isEmpty()?"0":mkdata.getString("ZZFBL");
						BigDecimal blnum = new BigDecimal(bl);
						BigDecimal num = new BigDecimal("100");
						BigDecimal num1 = new BigDecimal("1");
						BigDecimal zzf=	clf1.add(rgf1).divide(num1.subtract(blnum.divide(num)), 4).multiply(blnum.divide(num));
						mkBo.set("ZZF",zzf );
						mkBo.set("DJZZF", zzf.add(mkdj));
						mkBo.set("SITRUE", mkdata.getString("SITRUE"));
						mkBo.set("SLJSGZ", mkdata.getString("SLJSGZ"));
						//对模块的数量进行计算
						String jsgs=mkdata.getString("SLJSGZ");//模块数量计算公式；SLJSGZ
						Document document = Jsoup.parse(jsgs);
						String newQuation=document.text();
						if (!newQuation.equals("0")&&!newQuation.isEmpty()) {
							  for (String key : pMap.keySet()) {
									int num2 = newQuation.indexOf(key);
									if (num2 > -1) {
										newQuation = newQuation.replace(key, noMap.get(key));
									}
								}
							  FormulaEvaluator formulaEvaluator = workbookwl.getCreationHelper().createFormulaEvaluator();
								Cell cellB1 = sheet.createRow(bos.size()+lists.size()+zflist.size()+2).createCell(2);
								cellB1.setCellFormula(newQuation);
								formulaEvaluator.evaluateFormulaCell(cellB1);
								// 获取公式计算结果
								CellValue cellValue = formulaEvaluator.evaluate(cellB1);
								System.out.println("The result of the formula is: " + cellValue.getNumberValue());
								mkBo.set("MKSL", cellValue.getNumberValue());
//								double total1 = MKDJ * cellValue.getNumberValue();
//								double clftotal1 = CLF * cellValue.getNumberValue();
//								double rgftotal = RGF * cellValue.getNumberValue();
//								double wxtotal =WXWG * cellValue.getNumberValue();
//								double cgftotal = CGF * cellValue.getNumberValue();
//								double yftotal = ZFYF * cellValue.getNumberValue();
//							  DBSql.update(sql, new Object[] {MKDJ,CLF,RGF,WXWG,CGF,ZFYF,total1,clftotal1,rgftotal,wxtotal,cgftotal,yftotal,cellValue.getNumberValue()});
						  }else {
							  mkBo.set("MKSL", mkdata.getString("MKSL"));
						  }

						mkBo.set("GLPID", bindId);
						mkBo.set("XGBJDH", mdata.getString("APPLYNO"));
						ProcessInstance mpid=SDK.getProcessAPI().createBOProcessInstance("obj_338e4eb2168e4219811be2ab72f0e255", userContext.getUID(), "");
						SDK.getBOAPI().create("BO_EU_CPQ_MODULE_RECORD", mkBo, mpid.getId(), userContext.getUID());
						SDK.getBOAPI().create("BO_EU_CPQ_MODULE_RECORD_GRID", lists, mpid.getId(), userContext.getUID());
						SDK.getBOAPI().create("BO_EU_CPQ_MODULE_RECORD_STRAIGHT_HAIR", zflist, mpid.getId(), userContext.getUID());
						SDK.getBOAPI().create("BO_EU_CPQ_MODULE_RECORD_PARAMETERS", cslists, mpid.getId(), userContext.getUID());
						 Map<String, Object> maps = new HashMap<String, Object>();
					        maps.put("bindId", mpid.getId());
					        //maps.put("change", change);
					        ro.put("data", maps);
					} catch (Exception e) {
						throw e;
					}finally {
						try {
							workbookwl.close();
						} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
			  			 try {
							workbook.close();
						} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}

					}
				}

			}else {
				BO data=SDK.getBOAPI().query("BO_EU_CPQ_MODULE_MSG").addQuery("MKBM=", bh).addQuery("STATUS=", "启用").detail();


				if(null!=data) {
					//获取已存在的参数
					Map<String, String> map=new HashMap<String, String>();
					if(bos.size()>0) {
						for (BO bo : bos) {
							map.put(bo.getString("PARMENTIER_NO"), bo.getString("PARMENTIER_VALUE"))	;
						}
					}
					String pid=data.getBindId();
					List<BO> lists=SDK.getBOAPI().query("BO_EU_CPQ_MODULE_MSG_PRICE_PARAMETERS").bindId(pid).list();
					//存在参数后，判断参数在报价单的参数列表中是否存在
					Map<String, String> change=new HashMap<String, String>();
					if(lists.size()>0) {
						for (BO bo : lists) {
							String bm=bo.getString("PARMENTIER_NO");
							if(map.containsKey(bm)) {
								change.put(bo.getId(), map.get(bm));
							}
						}
					}
					 Map<String, Object> maps = new HashMap<String, Object>();
				        maps.put("bindId", pid);
				        maps.put("change", change);
				        ro.put("data", maps);


				}else {
					throw new BPMNError("005", "在模块清单中不存在该编码的模块");
				}

			}

			return ro.toString();
		} catch (Exception e) {
			throw e;
		}

	}

}
